/**
 * AggregativeIterator.java
 * @author: liuex
 * 2007-12-23 ����06:49:05
 *
 * note: 
 */
package org.lex.utils.collections;

import java.util.Iterator;

public class AggregativeIterator<T> implements Iterator<T> {
	private static final Iterator[] EMPTY = new Iterator[0];
	private Iterator<T>[] iters = null;
	private int index = 0;

	public AggregativeIterator(Iterator<T>... iterators) {
		if (null == iterators || 0 == iterators.length) {
			iterators = EMPTY;
		} else {
			this.iters = iterators;
			this.index = 1;
		}
	}

	@Override
	public boolean hasNext() {
		if (index >= iters.length)
			return false;
		Iterator<T> iter = iters[index];
		if (iter.hasNext())
			return true;
		index++;
		return this.hasNext();
	}

	@Override
	public T next() {
		return iters[index].next();
	}

	@Override
	public void remove() {
		iters[index].remove();
	}
}
